package com.example.qinghubeta;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.Toast;

public class Setting extends AppCompatActivity {

    RadioButton r1,r2,r3,r4;
    Button back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        r1 = findViewById(R.id.yanshi);
        r2 = findViewById(R.id.local);
        r3 = findViewById(R.id.pri);
        r4 = findViewById(R.id.aliyun);
        back = findViewById(R.id.button);


        SharedPreferences sharedPreferences = getSharedPreferences("auth",MODE_PRIVATE);
        int r = sharedPreferences.getInt("auth",1);
        if (r==1)r1.setChecked(true);else r1.setChecked(false);
        if (r==2)r2.setChecked(true);else r2.setChecked(false);
        if (r==3)r3.setChecked(true);else r3.setChecked(false);
        if (r==4)r4.setChecked(true);else r4.setChecked(false);

        SharedPreferences.Editor editor = sharedPreferences.edit();
        r1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SharedPreferences.Editor editor = sharedPreferences.edit();
                if (b) editor.putInt("auth",1);
                editor.apply();

            }
        });

        r2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SharedPreferences.Editor editor = sharedPreferences.edit();
                if (b) editor.putInt("auth",2);
                editor.apply();
            }
        });

        r3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SharedPreferences.Editor editor = sharedPreferences.edit();
                if (b) editor.putInt("auth",3);
                editor.apply();
            }
        });

        r4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SharedPreferences.Editor editor = sharedPreferences.edit();
                if (b) editor.putInt("auth",4);
                editor.apply();
            }
        });

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editor.apply();
                Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                startActivity(intent);
            }
        });
    }
}